<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{
            width: 300px;
            height: 500px;
            background-color: black;
        }
    </style>
</head>
<body>
    <button>开关</button>
    <div></div>

    <script>
        var oDiv = document.getElementsByTagName("div")[0];
        var but = document.getElementsByTagName("button")[0];

        var a = true;
        but.onclick = function(){
           if(a==true){
            oDiv.style.display = "none";
            a = false;
           }else if(a==false){
            oDiv.style.display = "block";
            a = true; 
           }
        }
    </script>
</body>
</html>